<template>
  <div class="tool">
    <div class="toolContent" @click="toolContentShow">
      <svg-icon icon-class="toolSvg"></svg-icon>
    </div>
    <div
        v-if="toolVisible"
        class="toolSvg"
        :class="{ selectSvg: selectTool == 1 }"
        @click="svgChange(1)"
    >
      <el-tooltip
          :open-delay="300"
          class="item"
          effect="dark"
          content="测量距离"
          placement="left"
      >
        <svg-icon icon-class="tool1"></svg-icon>
      </el-tooltip>
    </div>
    <div
        v-if="toolVisible"
        class="toolSvg"
        :class="{ selectSvg: selectTool == 2 }"
        @click="svgChange(2)"
    >
      <el-tooltip
          :open-delay="300"
          class="item"
          effect="dark"
          content="测量高度"
          placement="left"
      >
        <svg-icon icon-class="tool2"></svg-icon>
      </el-tooltip>
    </div>
    <div
        v-if="toolVisible"
        class="toolSvg"
        :class="{ selectSvg: selectTool == 3 }"
        @click="svgChange(3)"
    >
      <el-tooltip
          :open-delay="300"
          class="item"
          effect="dark"
          content="测量面积"
          placement="left"
      >
        <svg-icon icon-class="tool3"></svg-icon>
      </el-tooltip>
    </div>
    <div
        v-if="toolVisible"
        class="toolSvg"
        :class="{ selectSvg: selectTool == 4 }"
        @click="svgChange(4)"
    >
      <el-tooltip
          :open-delay="300"
          class="item"
          effect="dark"
          content="测量点位"
          placement="left"
      >
        <svg-icon icon-class="tool4"></svg-icon>
      </el-tooltip>
    </div>
    <div
        v-if="toolVisible"
        class="toolSvg"
        :class="{ selectSvg: selectTool == 5 }"
        @click="svgChange(5)"
    >
      <el-tooltip
          :open-delay="300"
          class="item"
          effect="dark"
          content="清空"
          placement="left"
      >
        <svg-icon icon-class="tool5"></svg-icon>
      </el-tooltip>
    </div>
    <div
        v-if="toolVisible"
        class="toolSvg"
        :class="{ selectSvg: selectTool == 6 }"
        @click="svgChange(6)"
    >
      <el-tooltip
          :open-delay="300"
          class="item"
          effect="dark"
          content="复位"
          placement="left"
      >
        <svg-icon icon-class="tool6"></svg-icon>
      </el-tooltip>
    </div>
  </div>
</template>

<script>
var viewerBox = null;
var tileSet = null;
var tileSetMode = null;
var TileLng, TileLat, TileHeight;

var map2D = null;

var handler1;

var drawingPolygon, drawingPolyline;

var tempEntities = [];
var tempLinesLong = 0;

export default {
  name: "flightWarningChart",
  props: {},
  components: {},
  data() {
    return {
      toolVisible: false,
      selectTool: 0,

      aim: 5,

      toolData: {},
    };
  },
  mounted() {
    viewerBox = viewer;
    console.log("viewerBox", viewerBox);
    this.initBus();
  },
  methods: {
    initBus() {
      this.$bus.on("exitTool", () => {
        this.svgChange(5);
      });
      this.$bus.on("aimChange", (aim) => {
        this.aim = aim;
      });
      this.$bus.on("getToolData", (data) => {
        this.toolData = data;
      });
    },
    destroyBus() {
      this.$bus.off("exitTool");
    },
    // 打开工具栏
    toolContentShow() {
      this.toolVisible = !this.toolVisible;
    },
    // 测量工具变换
    svgChange(val) {
      if (tilesetList.length > 0) {
        this.aim = 6;
      } else if (mymapList.length > 0) {
        this.aim = 5;
      } else {
        this.aim = 0;
      }

      switch (val) {
        case 1:
          // 测量距离 线
          if (this.aim == 6) {
            this.$message.info(
                "当前已加载三维模型，模型范围外区域测量结果将不再准确"
            );
          }
          this.setMode("drawLine", val);
          break;
        case 2:
          // 测量高度 三角
          if (this.aim != 6) {
            this.$message.warning("非三维不支持测量高度");
            this.selectTool = 0;
            return;
          }
          if (this.aim == 6) {
            this.$message.info(
                "当前已加载三维模型，模型范围外区域测量结果将不再准确"
            );
          }
          this.setMode("sanjiao", val);
          break;
        case 3:
          // 测量面积 面
          if (this.aim == 6) {
            this.$message.info(
                "当前已加载三维模型，模型范围外区域测量结果将不再准确"
            );
          }
          this.setMode("drawPloy", val);
          break;
        case 4:
          // 测量点位 点
          if (this.aim == 6) {
            this.$message.info(
                "当前已加载三维模型，模型范围外区域测量结果将不再准确"
            );
          }
          this.setMode("drawPoint", val);
          break;
        case 5:
          // 清空
          this.clearDrawingBoard();
          this.selectTool = 0;
          break;
        case 6:
          // 复位
          this.tileReset();
          this.selectTool = 0;
          break;

        default:
          console.log("其他工具");
          break;
      }
    },

    setMode(mode, modeVal) {
      let that = this;

      let tempPoints = [];
      tempLinesLong = 0;

      let scene = viewerBox.scene;
      if (that.isMeasure) {
        // that.$message.info("请先右击结束当前绘制");
        if (drawingPolygon != undefined) {
          viewerBox.entities.remove(drawingPolygon);
          drawingPolygon = null;
        }
        if (drawingPolyline != undefined) {
          viewerBox.entities.remove(drawingPolyline);
          drawingPolyline = null;
        }
        return false;
      }
      that.selectTool = modeVal;
      that.isMeasure = true;
      // that.clearEffects();
      if (mode == "drawPloy" && that.isMeasure) {
        this.$message.info("至少绘制三个点,右击结束");
        tempPoints = [];
        var timeoutID = null;
        var drawingPolygon = null;
        handler1 = new Cesium.ScreenSpaceEventHandler(scene.canvas);
        handler1.setInputAction(function (click) {
          console.log("clickPoly", click);
          clearTimeout(timeoutID);

          let ray = viewerBox.camera.getPickRay(click.position);
          // var cartesian = viewerBox.scene.globe.pick(ray, viewerBox.scene);

          // console.log("cartesian", cartesian);
          // if (that.aim == 6) {
          //   var cartesian = scene.pickPosition(click.position); //用于测坐标
          // }

          var cartesian = scene.pickPosition(click.position); //用于测坐标
          timeoutID = window.setTimeout(function () {
            if (cartesian && that.isMeasure) {
              tempPoints.push(cartesian);
              var tempLength = tempPoints.length;
              console.log("tempPoints", tempPoints);
              that.drawPoint(tempPoints[tempPoints.length - 1]);
              if (tempLength > 3) {
                // if (that.aim == 6) {
                tempPoints.splice(tempPoints.length - 2, 1);
                // }
                that.drawLine(
                    tempPoints[tempPoints.length - 2],
                    tempPoints[tempPoints.length - 1],
                    false
                );
                tempPoints.push(cartesian);
              } else if (tempLength > 1) {
                that.drawLine(
                    tempPoints[tempPoints.length - 2],
                    tempPoints[tempPoints.length - 1],
                    false
                );
              }
            }
          }, 200);
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

        handler1.setInputAction(function (click) {
          clearTimeout(timeoutID);
          that.$message.info("右击结束绘制");
        }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

        handler1.setInputAction(function (click) {
          console.log("cartesian ", cartesian);
          let ray = viewerBox.camera.getPickRay(click.position);
          // var cartesian = viewerBox.scene.globe.pick(ray, viewerBox.scene);
          // if (that.aim == 6) {
          //   var cartesian = scene.pickPosition(click.position); //用于测坐标
          // }

          var cartesian = scene.pickPosition(click.position); //用于测坐标
          if (cartesian && that.isMeasure) {
            var tempLength = tempPoints.length;
            if (tempLength < 3) {
              alert("请选择3个以上的点再执行闭合操作命令");
            } else {
              tempPoints.pop();
              that.drawLine(
                  tempPoints[0],
                  tempPoints[tempPoints.length - 1],
                  false
              );
              var res = that.drawPoly(tempPoints);
              var ent = res[1];
              ent.position = that.CalPolygonMid(tempPoints);
              if (res[0] > 1000000) {
                ent.label.text = (res[0] / 1000 / 1000).toFixed(1) + "km²";
              } else {
                ent.label.text = res[0].toFixed(1) + "m²";
              }

              // var node = treeObj.getNodeByParam("id", 3, null);
              // var newNode = { id: ent.id, pId: 1, name: "未命名测量" };
              // treeObj.addNodes(node, -1, newNode);

              tempPoints = [];
              that.clearEffects();
              that.isMeasure = false;

              if (drawingPolygon != undefined) {
                viewerBox.entities.remove(drawingPolygon);
                drawingPolygon = null;
              }
            }
          }
          that.selectTool = 0;
        }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
        handler1.setInputAction(function (movement) {
          var cartesian = scene.pickPosition(movement.endPosition);
          if (cartesian && that.isMeasure) {
            console.log("move", tempPoints);
            if (tempPoints.length <= 1) {
              //TooltipDiv.showAt(movement.endPosition, '点击添加点');
            } else {
              if (drawingPolygon) {
                tempPoints.pop();
                tempPoints.push(cartesian);
              } else {
                tempPoints.push(cartesian);
                var dynamicPositions = new Cesium.CallbackProperty(function () {
                  var bbb = new Cesium.PolygonHierarchy(tempPoints);
                  return bbb;
                }, false);
                drawingPolygon = viewerBox.entities.add({
                  polygon: {
                    hierarchy: dynamicPositions,
                    material: Cesium.Color.DODGERBLUE.withAlpha(0.2),
                    perPositionHeight: true,
                    disableDepthTestDistance: 1000, //优先级
                  },
                });
              }
            }
          }
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
      } else if ("drawPoint" == mode && that.isMeasure) {
        that.$message.info("点击你要测量的点");
        handler1 = new Cesium.ScreenSpaceEventHandler(scene.canvas);
        handler1.setInputAction(function (click) {
          console.log("cartesian ", cartesian);
          let ray = viewerBox.camera.getPickRay(click.position);
          // var cartesian = viewerBox.scene.globe.pick(ray, viewerBox.scene);
          // if (that.aim == 6) {
          //   var cartesian = scene.pickPosition(click.position); //用于测坐标
          // }

          var cartesian = scene.pickPosition(click.position); //用于测坐标
          if (cartesian && that.isMeasure) {
            that.drawVPoint(cartesian);

            tempPoints = [];
            that.clearEffects();
            that.isMeasure = false;
          }
          that.selectTool = 0;
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
      } else if ("drawLine" == mode && that.isMeasure) {
        // that.$message.info("右击结束绘制");
        tempPoints = [];
        var positionArr = [];
        var drawingPolyline = null;
        var timeoutID = null;
        handler1 = new Cesium.ScreenSpaceEventHandler(scene.canvas);
        handler1.setInputAction(function (click) {
          clearTimeout(timeoutID);
          timeoutID = window.setTimeout(function () {
            console.log("cartesian ", cartesian);
            let ray = viewerBox.camera.getPickRay(click.position);
            // var cartesian = viewerBox.scene.globe.pick(ray, viewerBox.scene);
            // if (that.aim == 6) {
            //   var cartesian = scene.pickPosition(click.position); //用于测坐标
            // }

            var cartesian = scene.pickPosition(click.position); //用于测坐标
            console.log("cartesian ", cartesian);

            if (cartesian && that.isMeasure) {
              console.log(cartesian);
              tempPoints.push(cartesian);
              var tempLength = tempPoints.length;
              that.drawPoint(tempPoints[tempPoints.length - 1]);
              if (tempLength > 1) {
                that.drawLine(
                    tempPoints[tempPoints.length - 2],
                    tempPoints[tempPoints.length - 1],
                    true
                );
                if (drawingPolyline != undefined) {
                  viewerBox.entities.remove(drawingPolyline);
                  drawingPolyline = null;
                  positionArr = [];
                }
              }
            }
          }, 200);
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        handler1.setInputAction(function (click) {
          clearTimeout(timeoutID);
          that.$message.info("右击结束绘制");
        }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

        handler1.setInputAction(function (click) {
          if (that.isMeasure) {
            var ent = viewerBox.entities.add({
              position: tempPoints[tempPoints.length - 1],
              label: {
                text: "总长：" + tempLinesLong.toFixed(1) + "m",
                font: "22px Helvetica",
                fillColor: Cesium.Color.BLACK,
                outlineColor: Cesium.Color.WHITE,
                outlineWidth: 2,
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                pixelOffset: new Cesium.Cartesian2(1.0, -10.0),
                disableDepthTestDistance: 100000,
                scaleByDistance: new Cesium.NearFarScalar(3.0e2, 1, 1.0e4, 1),
              },
            });
            if (drawingPolyline != undefined) {
              viewerBox.entities.remove(drawingPolyline);
              drawingPolyline = null;
              positionArr = [];
            }
            tempEntities.push(ent);
            tempPoints = [];
            tempLinesLong = 0;
            that.clearEffects();
            that.isMeasure = false;
          }
          that.selectTool = 0;
        }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

        handler1.setInputAction(function (movement) {
          var cartesian = scene.pickPosition(movement.endPosition);
          if (cartesian && that.isMeasure) {
            if (tempPoints.length == 0) {
            } else {
              //更新entity

              if (positionArr.length == 0) {
                positionArr.push(tempPoints[tempPoints.length - 1]);
              }
              if (drawingPolyline) {
                positionArr.pop();
                positionArr.push(cartesian);
              } else {
                console.log(1111);
                positionArr.push(cartesian);
                var dynamicPositions = new Cesium.CallbackProperty(function () {
                  return positionArr;
                }, false);
                var lineOpts = {
                  polyline: {
                    positions: dynamicPositions,
                    width: 4.0,
                    material: new Cesium.PolylineOutlineMaterialProperty({
                      color: Cesium.Color.DODGERBLUE,
                      outlineWidth: 1,
                      outlineColor: Cesium.Color.WHITE,
                    }),
                    // depthFailMaterial : new Cesium.PolylineDashMaterialProperty({
                    // 	color : Cesium.Color.DARKBLUE,
                    // 	dashLength: 5.0
                    // }),
                    // disableDepthTestDistance : 100000//优先级
                  },
                };
                drawingPolyline = viewerBox.entities.add(lineOpts);
              }
            }
          }
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
      } else if ("sanjiao" == mode && that.isMeasure) {
        console.log("三角");
        var drawingPolyline = null;
        tempPoints = [];
        handler1 = new Cesium.ScreenSpaceEventHandler(scene.canvas);
        handler1.setInputAction(function (click) {
          console.log("handlerClick", click);
          var cartesian = scene.pickPosition(click.position); //用于测坐标
          if (cartesian && that.isMeasure) {
            tempPoints.push(cartesian);
            var tempLength = tempPoints.length;
            that.drawPoint(tempPoints[tempPoints.length - 1]);
            if (tempLength > 1) {
              var cartographic1 = Cesium.Cartographic.fromCartesian(
                  tempPoints[0]
              );
              var cartographic2 = Cesium.Cartographic.fromCartesian(
                  tempPoints[1]
              );
              var tp3 = Cesium.Cartesian3.fromRadians(
                  cartographic2.longitude,
                  cartographic2.latitude,
                  cartographic1.height
              );

              that.drawLine(tempPoints[0], tp3, true);
              that.drawLine(tempPoints[1], tp3, true);
              that.drawLine(tempPoints[1], tempPoints[0], false);

              tempPoints = [];
              that.clearEffects();
              that.isMeasure = false;
              //移除entity
              if (drawingPolyline != undefined) {
                viewerBox.entities.remove(drawingPolyline);
              }

              that.selectTool = 0;
            }
          }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        handler1.setInputAction(function (movement) {
          var cartesian = scene.pickPosition(movement.endPosition);
          if (cartesian && that.isMeasure) {
            if (tempPoints.length == 0) {
              return;
            } else if (tempPoints.length == 1) {
              var cartographic1 = Cesium.Cartographic.fromCartesian(
                  tempPoints[0]
              );
              var cartographic2 = Cesium.Cartographic.fromCartesian(cartesian);
              var tp3 = Cesium.Cartesian3.fromRadians(
                  cartographic2.longitude,
                  cartographic2.latitude,
                  cartographic1.height
              );

              //更新entity
              if (drawingPolyline != undefined)
                viewerBox.entities.remove(drawingPolyline);
              var lineOpts = {
                polyline: {
                  positions: [tempPoints[0], cartesian, tp3, tempPoints[0]],
                  width: 10.0,
                  material: new Cesium.PolylineGlowMaterialProperty({
                    color: Cesium.Color.DODGERBLUE.withAlpha(0.5),
                    RimLighting: Cesium.Color.BLACK.withAlpha(0.4),
                  }),
                  disableDepthTestDistance: 100000, //优先级
                },
              };
              drawingPolyline = viewerBox.entities.add(lineOpts);
            }
          }
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
      }
    },

    clearEffects() {
      if (handler1 != null) {
        handler1.destroy();
      }
    },
    drawPoint(point) {
      console.log("point", point);
      var entity = viewerBox.entities.add({
        position: point,
        clampToGround: true,
        attachPolygon: true,
        point: {
          pixelSize: 10,
          color: Cesium.Color.WHITE,
          translucencyByDistance: new Cesium.NearFarScalar(1.0e2, 1, 1.5e3, 0),
          disableDepthTestDistance: 1000000000, //优先级
        },
      });
      tempEntities.push(entity);
    },
    drawVPoint(point) {
      var cartographic = Cesium.Cartographic.fromCartesian(point);
      var pLon = Cesium.Math.toDegrees(cartographic.longitude); //cartographic弧度，currentClickLon度
      var pLat = Cesium.Math.toDegrees(cartographic.latitude);
      var pHei = cartographic.height.toFixed(1);
      var entity = viewerBox.entities.add({
        position: point,
        clampToGround: true,
        attachPolygon: true,
        zIndex: 999,
        billboard: {
          image: require("./img/mark.png"),
          scale: 0.1,
          scaleByDistance: new Cesium.NearFarScalar(300, 1.0, 50000, 0.0),
          disableDepthTestDistance: Number.POSITIVE_INFINITY,
        },
        label: {
          text: pLon.toFixed(8) + "，" + pLat.toFixed(8) + "，" + pHei,
          font: "16pt sans-serif",
          fillColor: Cesium.Color.BLACK,
          outlineColor: Cesium.Color.WHITE,
          outlineWidth: 2,
          style: Cesium.LabelStyle.FILL_AND_OUTLINE,
          pixelOffset: new Cesium.Cartesian2(0.0, -30),
          pixelOffsetScaleByDistance: new Cesium.NearFarScalar(
              500,
              1.0,
              10000,
              0.0
          ),
          scaleByDistance: new Cesium.NearFarScalar(500, 1.0, 10000, 1.0),
        },
      });
      tempEntities.push(entity);

      // var node = treeObj.getNodeByParam("id", 1, null);
      // var newNode = { id: entity.id, pId: 1, name: "未命名标注" };
      // treeObj.addNodes(node, -1, newNode);
    },
    drawLine(point1, point2, showDistance) {
      if (showDistance) {
        var distance = this.getFlatternDistance(point1, point2);
        tempLinesLong += distance;
        var entity = viewerBox.entities.add({
          position: {
            x: (point1.x + point2.x) / 2,
            y: (point1.y + point2.y) / 2,
            z: (point1.z + point2.z) / 2,
          },
          polyline: {
            positions: [point1, point2],
            width: 3.0,
            material: Cesium.Color.DODGERBLUE,
            depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
              color: Cesium.Color.DODGERBLUE,
              dashLength: 5.0,
            }),
            disableDepthTestDistance: 100000, //优先级
          },
          label: {
            text: distance.toFixed(1) + "m",
            font: "22px Helvetica",
            fillColor: Cesium.Color.BLACK,
            outlineColor: Cesium.Color.WHITE,
            outlineWidth: 2,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
            pixelOffset: new Cesium.Cartesian2(0.0, -10.0),
            disableDepthTestDistance: 100000, //优先级
            scaleByDistance: new Cesium.NearFarScalar(3.0e2, 1, 1.0e4, 1),
          },
        });
        tempEntities.push(entity);
        // var node = treeObj.getNodeByParam("id", 2, null);
        // var newNode = { id: entity.id, pId: 1, name: "未命名测量" };
        // treeObj.addNodes(node, -1, newNode);
      } else {
        var entity = viewerBox.entities.add({
          polyline: {
            positions: [point1, point2],
            width: 3.0,
            material: Cesium.Color.DODGERBLUE,
            depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
              color: Cesium.Color.DODGERBLUE,
              dashLength: 5.0,
            }),
            disableDepthTestDistance: 100000, //优先级
          },
        });
        tempEntities.push(entity);
      }
    },
    drawPoly(points) {
      var entity = viewerBox.entities.add({
        polygon: {
          hierarchy: new Cesium.PolygonHierarchy(points),
          material: Cesium.Color.DODGERBLUE.withAlpha(0.2),
          perPositionHeight: true,
          disableDepthTestDistance: 1000, //优先级
        },
        label: {
          text: "",
          font: "20px Helvetica",
          fillColor: Cesium.Color.BLACK,
          outlineColor: Cesium.Color.WHITE,
          outlineWidth: 2,
          style: Cesium.LabelStyle.FILL_AND_OUTLINE,
          horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
          pixelOffset: new Cesium.Cartesian2(0.0, 0.0),
          disableDepthTestDistance: 100000, //优先级
          scaleByDistance: new Cesium.NearFarScalar(3.0e2, 1, 1.0e4, 1),
        },
      });

      var s = this.CalPolygonArea(entity);
      console.log(s);
      tempEntities.push(entity);
      return [s, entity];
    },
    CalPolygonArea(theEntity) {
      var polygon = theEntity.polygon;
      var hierarchy = polygon.hierarchy._value;

      // "indices" here defines an array, elements of which defines the indice of a vector
      // defining one corner of a triangle. Add up the areas of those triangles to get
      // an approximate area for the polygon
      var indices = Cesium.PolygonPipeline.triangulate(
          hierarchy.positions,
          hierarchy.holes
      );
      var area = 0; // In square kilometers

      for (var i = 0; i < indices.length; i += 3) {
        var vector1 = hierarchy.positions[indices[i]];
        var vector2 = hierarchy.positions[indices[i + 1]];
        var vector3 = hierarchy.positions[indices[i + 2]];

        // These vectors define the sides of a parallelogram (double the size of the triangle)
        var vectorC = Cesium.Cartesian3.subtract(
            vector2,
            vector1,
            new Cesium.Cartesian3()
        );
        var vectorD = Cesium.Cartesian3.subtract(
            vector3,
            vector1,
            new Cesium.Cartesian3()
        );

        // Area of parallelogram is the cross product of the vectors defining its sides
        var areaVector = Cesium.Cartesian3.cross(
            vectorC,
            vectorD,
            new Cesium.Cartesian3()
        );

        // Area of the triangle is just half the area of the parallelogram, add it to the sum.
        area += Cesium.Cartesian3.magnitude(areaVector) / 2.0;
      }
      return area;
    },
    CalPolygonMid(points) {
      var c = 0,
          k = 0,
          g = 0;
      for (var i = 0; i < points.length; i++) {
        c += points[i].x;
        k += points[i].y;
        g += points[i].z;
      }
      return {
        x: c / points.length,
        y: k / points.length,
        z: g / points.length,
      };
    },

    getFlatternDistance(p1, p2) {
      //  		console.log(Cesium.Cartesian3.distance(new Cesium.Cartesian3(p1.x,p1.y,p1.z),new Cesium.Cartesian3(p2.x,p2.y,p2.z)))
      return Math.sqrt(
          (p1.x - p2.x) * (p1.x - p2.x) +
          (p1.y - p2.y) * (p1.y - p2.y) +
          (p1.z - p2.z) * (p1.z - p2.z)
      );
    },

    /**
     * 清除地图痕迹
     */
    clearDrawingBoard() {
      var primitives = viewerBox.entities;
      for (var i = 0; i < tempEntities.length; i++) {
        primitives.remove(tempEntities[i]);
      }
      tempEntities = [];
    },
    tileReset() {
      console.log("toolData", this.toolData, this.aim);

      if (this.aim == 5) {
        viewerBox.camera.flyTo({
          destination: Cesium.Cartesian3.fromDegrees(
              +this.toolData.position[0],
              +this.toolData.position[1],
              1000
          ),
        });
      } else if (this.aim == 6) {
        viewerBox.flyTo(tilesetList[tilesetList.length - 1]);
      } else {
        this.$message.warning("请选中需要查看三维或正射成品");
        return;
      }
    },
  },
  computed: {},
  watch: {},
  beforeDestroy() {
    this.destroyBus();
  },
};
</script>

<style lang='scss' scoped>
.tool {
  .toolContent {
    margin-top: 5px;
    width: 30px;
    color: #ffffff;
    background: #14375d;
    border: 1px solid #1989be;
    width: 32px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    cursor: pointer;
  }
  .toolSvg {
    width: 30px;
    color: #ffffff;
    background: #083762;
    border: 1px solid #1989be;
    width: 32px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-top: none;
    border-bottom: none;
    &:hover {
      background-color: #0356a2;
    }
    &.selectSvg {
      background-color: #0356a2;
    }
    &:last-child {
      border-bottom: 1px solid #1989be;
    }
    cursor: pointer;
  }
}
</style>
